package com.dnf.dao.impl;

import java.util.List;

import org.apache.ibatis.session.SqlSession;

import com.dnf.bean.Goods;
import com.dnf.dao.GoodsDao;

/**
 * @author Administrator
 *
 */
public class GoodsDaoImpl implements GoodsDao{


	@Override
	public int addGoods(SqlSession session, Goods goods) {
		String statement = "com.dnf.mapping.goodsMapper.addGoods";
		int result = 0;
		if(getGoodsByNameAndDate(session, goods)<1)		  
		  result = session.insert(statement, goods);
		session.commit();
		return result;
	}

	@Override
	public Goods getGoods(SqlSession session, int id) {
		String statement = "com.dnf.mapping.goodsMapper.getGoods";
		Goods result = session.selectOne(statement, id);
		return result;
	}


	@Override
	public List<Goods> getAllGoods(SqlSession session) {
		String statement = "com.dnf.mapping.goodsMapper.getAllGoods";
		List <Goods> goodsList = session.selectList(statement);
		return goodsList;
	}
	@Override
	public int getGoodsByNameAndDate(SqlSession session, Goods goods) {
		String statement = "com.dnf.mapping.goodsMapper.getGoodsByNameAndDate";
		int result = session.selectOne(statement, goods);
		return result;
	}

}
